package io.gitee.kotle.android.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import java.lang.reflect.Type


interface IRecyclerViewAdapter<Data> {


    fun onCreateRecyclerViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder<Data, *>

    fun onBindRecyclerViewHolder(
        holder: RecyclerViewHolder<Data, *>, position: Int, payloads: MutableList<Any>,
        isScrollEnd: Boolean,
        item: Data?
    )

    fun getRecyclerViewItemViewType(position: Int, data: Data?): Int

    fun onRecyclerViewHolderAttachedToWindow(holder: RecyclerViewHolder<Data, *>)

    fun onRecyclerViewHolderDetachedFromWindow(holder: RecyclerViewHolder<Data, *>)

    fun onRecyclerViewHolderRecycled(holder: RecyclerViewHolder<Data, *>)

    fun onRecyclerViewHolderFailedToRecycleView(holder: RecyclerViewHolder<Data, *>)

    fun <DataType : Data, Holder : RecyclerViewHolder<DataType, *>> register(
        holderCls: Class<Holder>,
        viewType: Int = RecyclerView.INVALID_TYPE,
    ) = register(RecyclerRegisterInfo.HolderClass(holderCls, viewType))


    fun <DataType : Data, Holder : RecyclerViewHolder<DataType, *>> register(
        holderClassInfo: RecyclerRegisterInfo.HolderClass<DataType, Holder>
    ): Boolean

    fun <DataType : Data> registerData(
        dataType: Class<DataType>,
        viewType: Int = RecyclerView.INVALID_TYPE,
        onCreateHolderListener: Function3<@ParameterName("inflater") LayoutInflater,
                @ParameterName("parent") ViewGroup,
                @ParameterName("viewType") Int,
                RecyclerViewHolder<DataType, *>>
    ) = registerData(
        RecyclerRegisterInfo.HolderDataType(
            dataType,
            viewType,
            onCreateHolderListener
        )
    )

    fun <DataType : Data> registerData(dataTypeInfo: RecyclerRegisterInfo.HolderDataType<DataType>): Boolean

    fun <DataType : Data, Holder : RecyclerViewHolder<DataType, *>> unRegister(holderClass: Class<Holder>?)


    fun <DataType : Data> unRegisterData(dataType: Class<DataType>?)


    fun setOnHolderClickListener(
        clickId: Int? = null,
        listener: ((holder: RecyclerViewHolder<Data, *>, clickView: View) -> Unit)
    )

    fun setOnHolderLongClickListener(
        clickId: Int? = null,
        listener: ((holder: RecyclerViewHolder<Data, *>, clickView: View) -> Unit)
    )

    fun setOnScrollEndListener(l: Function1<Int, Unit>?)

    fun getItemData(position: Int): Data?
}